package com.capybara.account.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.DataChangeRecorderInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分页配置
 *
 * @author wangguochao
 */
@Configuration
@Slf4j
@AllArgsConstructor
public class MyBatisPlusConfig {

    /**
     * 添加分页插件
     *
     * @return mybatis plus 拦截器
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        PaginationInnerInterceptor interceptor1 = new PaginationInnerInterceptor(DbType.POSTGRE_SQL);
        DataChangeRecorderInnerInterceptor interceptor2 = new DataChangeRecorderInnerInterceptor();
             interceptor1.setOverflow(true);// 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(interceptor2);// 数据变更记录
        interceptor.addInnerInterceptor(interceptor1);//如果配置多个插件,切记分页最后添加
        return interceptor;
    }
}
